package com.io.testIO;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-04-13 17:12:11
 */
public class TestFileUtil {

    public static void test01() {
        boolean isWin = FileUtil.isWindows();
        System.out.println(isWin);
    }

    public static void test02() {
        boolean dir = FileUtil.isDirectory("D:/test02_hutool_util");
        System.out.println(dir);
    }

    public static void test03() {
        File dir = FileUtil.mkdir("D:/test02_hutool_util/cyd/li");
        File cyd = FileUtil.touch("D:/test02_hutool_util/cyd/cyd.txt");
        boolean isDir = dir.isDirectory();
        boolean isFile = cyd.isFile();
        System.out.println("li是文件夹吗？：" + isDir);
        System.out.println("cyd是文件吗？：" + isFile);
    }

    public static void test04() {
        File file = FileUtil.file("D:/test02_hutool_util/cyd/cyd.txt");

        BufferedInputStream inputStream = FileUtil.getInputStream(file);
        BufferedOutputStream outputStream = FileUtil.getOutputStream("D:/test02_hutool_util/cyd/cyd2.txt");
        IoUtil.copy(inputStream, outputStream, IoUtil.DEFAULT_LARGE_BUFFER_SIZE);
        IoUtil.writeUtf8(outputStream, false, "\nhello");
        IoUtil.close(inputStream);
        IoUtil.close(outputStream);
    }

    public static void test05() {
        File file = FileUtil.file("D:/test02_hutool_util/cyd/cyd.txt");
        FileUtil.appendUtf8String("\naaabbbccc", file);
    }

    public static void main(String[] args) {
        test05();
    }
}
